<?php

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Details extends Model
{
    protected $table = 'details';

    /**
     * 指示模型是否自动维护时间戳
     *
     * @var bool
     */
    public $timestamps = true;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'order_sn','user_id', 'invitee_user_id', 'money', 'reward' , 'status','expect_at'
    ];

    /**
     * 为数组 / JSON 序列化准备日期。
     *
     * @param \DateTimeInterface $date
     * @return string
     */
    protected function serializeDate(\DateTimeInterface $date)
    {
        return Carbon::instance($date)->toDateTimeString();
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * 用户信息
     */
    public function User()
    {
        return $this->hasOne(Users::class , 'id' , 'user_id')->select(['id' , 'name' , 'phone']);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     * 被邀请人
     */
    public function inviteeUser()
    {
        return $this->hasOne(Users::class , 'id' , 'invitee_user_id')->select(['id' , 'name' , 'phone']);
    }

    /**
     * 应该转换为日期格式的属性.
     *
     * @var array
     */
    protected $dates = [
        'expect_at',
    ];
}
